# download CCLE gistic data for kinase genes from cBioPortal
# jamesc@icr.ac.uk, 12th Jan 2015

setwd("/Users/jamesc/Dropbox/Intercell_II_analysis/icr-intercell/resources/")

require(cgdsr)
# Create CGDS object
mycgds = CGDS("http://www.cbioportal.org/public-portal/")

test(mycgds)

kinase_genes <- c(
	"SCYL3",
	"FGR",
	"AK2",
	"CAMKK1",
	"PDK4",
	"PRKAR2B",
	"PDK2",
	"MAP3K14",
	"MAP3K9",
	"AGK",
	"DBF4",
	"CDKL3",
	"MARK4",
	"MATK",
	"CDKL5",
	"CAMK1G",
	"CDK11A",
	"CDK11A",
	"NADK",
	"DYRK4",
	"BTK",
	"FYN",
	"PIK3C2A",
	"MAP4K3",
	"MAP4K5",
	"CLK1",
	"PRKCH",
	"INSRR",
	"VRK2",
	"MUSK",
	"MAP2K3",
	"DAPK2",
	"FLT4",
	"PI4K2B",
	"TRIO",
	"PNKP",
	"PHKA2",
	"EPHA3",
	"ROS1",
	"MAPK9",
	"PIK3CB",
	"KCNH2",
	"EIF2AK2",
	"CDK14",
	"CAMK2B",
	"RIOK2",
	"DGKG",
	"ALDH18A1",
	"CDK17",
	"STYK1",
	"WNK1",
	"TNK2",
	"LTK",
	"SPHK2",
	"ADCK1",
	"HIPK2",
	"PKN2",
	"DGKA",
	"ERBB3",
	"MYLK",
	"MAP2K4",
	"SLK",
	"PRKCQ",
	"CDK13",
	"GOLGA5",
	"FGFR2",
	"PFKP",
	"PHKA1",
	"PKM",
	"PRKCZ",
	"ROCK1",
	"PDK3",
	"FGFR3",
	"COASY",
	"IP6K2",
	"MAST4",
	"NUCKS1",
	"TGFBR3",
	"MAPK6",
	"GUCY2C",
	"IKBKAP",
	"TESK2",
	"CSNK2A2",
	"CAMK2A",
	"EPHA8",
	"MAP4K4",
	"RPS6KA2",
	"TRIB2",
	"MYO3B",
	"PRKACA",
	"RPS6KA6",
	"SPEG",
	"MARK2",
	"STK10",
	"ALPK1",
	"MAP3K13",
	"NUAK1",
	"MARK3",
	"DLG1",
	"MAP2K7",
	"DGKD",
	"PAK3",
	"FGFR1",
	"ARAF",
	"PIK3C3",
	"N4BP2",
	"MKNK1",
	"EPHA6",
	"MOK",
	"MAGI3",
	"STK17B",
	"STRADB",
	"DLG3",
	"GSK3B",
	"ULK2",
	"MAP3K4",
	"CPNE3",
	"MAST2",
	"EIF2AK1",
	"ITPKC",
	"NLK",
	"AURKA",
	"MAPKAPK5",
	"IRAK3",
	"ZAK",
	"TRPM7",
	"TYRO3",
	"XYLB",
	"MAP3K1",
	"MYO3A",
	"SRPK1",
	"JAK2",
	"ABL1",
	"CDC7",
	"MAST3",
	"PRKY",
	"MKNK2",
	"CRKL",
	"MAPK1",
	"DGCR14",
	"ADRBK2",
	"CHKB",
	"TAB1",
	"CERK",
	"CDKL1",
	"ITPK1",
	"VRK1",
	"RPS6KA5",
	"PCK2",
	"SGK2",
	"STK4",
	"PTK6",
	"TRIB3",
	"CSNK2A1",
	"MYLK2",
	"HCK",
	"PAK7",
	"RIOK3",
	"GUCY2F",
	"PRPS2",
	"BMX",
	"PIM2",
	"PGK1",
	"CDK16",
	"CDADC1",
	"STK24",
	"FLT1",
	"DGKH",
	"MAPK3",
	"PHKB",
	"NME3",
	"NME4",
	"EEF2K",
	"BCKDK",
	"CSK",
	"SGK3",
	"PDGFRL",
	"RIPK2",
	"IKBKB",
	"STK3",
	"MAP4K1",
	"CKM",
	"DMPK",
	"VRK3",
	"AURKC",
	"DYRK1B",
	"AKT2",
	"PRKD2",
	"TYK2",
	"MAST1",
	"JAK3",
	"PIK3R2",
	"GSK3A",
	"CDK6",
	"PIK3CG",
	"MET",
	"LMBR1",
	"EPHB6",
	"PRKAG2",
	"GCK",
	"LIMK1",
	"TGFBR1",
	"AK1",
	"TESK1",
	"PIP5K1B",
	"MAPK8",
	"BMPR1A",
	"MAP3K8",
	"RPS6KB1",
	"GALK1",
	"MPP2",
	"PRKAR1A",
	"EFNB3",
	"MAP2K6",
	"MAPK10",
	"HIPK3",
	"CHKA",
	"GTF2H1",
	"MVK",
	"CAMKK2",
	"CDKN1B",
	"PRKAB1",
	"FRK",
	"MAK",
	"MAPK14",
	"STK38",
	"ICK",
	"PTK7",
	"PRPF4B",
	"TTK",
	"NME5",
	"COL4A3BP",
	"CLK4",
	"ITK",
	"CSNK1A1",
	"PDGFRB",
	"GRK7",
	"PFKFB4",
	"PRKAR2A",
	"NEK11",
	"MAPKAPK3",
	"ACVR2B",
	"NEK4",
	"DGUOK",
	"PIKFYVE",
	"ZAP70",
	"ACVR1",
	"NRBP1",
	"PRKAG3",
	"STK16",
	"PASK",
	"STK25",
	"PRKD3",
	"AAK1",
	"EPHA4",
	"MARK1",
	"TNNI3K",
	"AKT3",
	"CDK18",
	"PIK3R3",
	"NEK2",
	"RPS6KA1",
	"STK11",
	"SGK1",
	"TRPM6",
	"TJP2",
	"NEK6",
	"NEK9",
	"PANK3",
	"TEK",
	"MASTL",
	"PTK2B",
	"TEX14",
	"PIK3CA",
	"ACVR2A",
	"FLT3",
	"TAF1L",
	"TAF1L",
	"CIT",
	"CDKN2C",
	"PKN1",
	"CDK2",
	"NRK",
	"ACVR1C",
	"ADCK4",
	"PFKFB2",
	"CKS2",
	"PCK1",
	"NAGK",
	"PACSIN1",
	"CDKN1A",
	"RIOK1",
	"GRK4",
	"SRMS",
	"PANK2",
	"STK35",
	"TSKS",
	"WNK4",
	"PRKCG",
	"MAP2K2",
	"IPPK",
	"DYRK2",
	"FGFRL1",
	"PKMYT1",
	"KDR",
	"EIF2AK4",
	"TTBK2",
	"CDKN2D",
	"RIPK3",
	"CDKN1C",
	"PRKCSH",
	"STK33",
	"PAK4",
	"UCK1",
	"MAP3K10",
	"PNCK",
	"MPP1",
	"LATS1",
	"CKMT2",
	"PRKAB2",
	"RAF1",
	"PRKAA1",
	"GUCY2D",
	"DLG4",
	"CDK8",
	"PIK3C2B",
	"DSTYK",
	"DCLK1",
	"EPHB2",
	"CSNK1G2",
	"ADCK2",
	"CDK7",
	"IRAK2",
	"CAMK1",
	"ROCK2",
	"ERN2",
	"STK26",
	"PDGFRA",
	"RFK",
	"TAOK3",
	"SRPK2",
	"EPHA7",
	"MAP3K7",
	"AMHR2",
	"CDK4",
	"ACVR1B",
	"PKIB",
	"TEC",
	"RNASEL",
	"NEK3",
	"DGKB",
	"HUS1",
	"ALPK3",
	"CIB2",
	"BLK",
	"RPS6KC1",
	"CDK9",
	"PIM1",
	"RIPK1",
	"DDR1",
	"NEK1",
	"MAP2K5",
	"ITPKA",
	"PAK6",
	"BRDT",
	"KHK",
	"CDK15",
	"PRKG2",
	"BMPR1B",
	"BMP2K",
	"CDKL2",
	"PAPSS1",
	"PIK3C2G",
	"ETNK1",
	"ACVRL1",
	"MAP3K12",
	"TSSK4",
	"AK7",
	"IGF1R",
	"ULK3",
	"NTRK3",
	"MYLK3",
	"PDPK1",
	"KSR1",
	"SKAP1",
	"MINK1",
	"PIK3R5",
	"CSNK1D",
	"FN3KRP",
	"MAPK4",
	"ERBB2",
	"BRD4",
	"PFKL",
	"HUNK",
	"SIK1",
	"SCYL1",
	"AKT1",
	"LMTK3",
	"EPHA2",
	"PLK4",
	"MAP3K6",
	"PRKACB",
	"NME7",
	"UCK2",
	"ABL2",
	"PI4KB",
	"PIP5K1A",
	"DYRK3",
	"EFNA3",
	"PKLR",
	"KIAA1804",
	"ITPKB",
	"GUK1",
	"CDC42BPA",
	"ETNK2",
	"CALM2",
	"DGKQ",
	"EPHA5",
	"TBCK",
	"CAMK2D",
	"PLK2",
	"PIK3R1",
	"MYLK4",
	"TTBK1",
	"EGFR",
	"TLK2",
	"EPHA1",
	"CASK",
	"PRPS1",
	"PSKH2",
	"AK3",
	"CDKN2B",
	"NTRK2",
	"COMMD3",
	"CAMK2G",
	"PAK1",
	"ATM",
	"CHEK1",
	"TAOK2",
	"LATS2",
	"DLG2",
	"PIP4K2A",
	"CRIM1",
	"IPMK",
	"TWF1",
	"MAGI1",
	"CSNK1G3",
	"NEK7",
	"FER",
	"HSPB8",
	"PDK1",
	"UHMK1",
	"CAMK4",
	"PFKM",
	"PANK1",
	"STK32B",
	"MERTK",
	"AK5",
	"PRKCA",
	"LRRK1",
	"TNIK",
	"EPHB1",
	"CDK19",
	"PI4K2A",
	"ADK",
	"DCK",
	"CDK20",
	"HK1",
	"MAPK13",
	"PHKG2",
	"GALK2",
	"BUB1B",
	"SMG1",
	"FUK",
	"KIT",
	"DYRK1A",
	"DGKI",
	"BRAF",
	"PANK4",
	"PFKFB1",
	"PINK1",
	"ADPGK",
	"HK2",
	"PSKH1",
	"NPR2",
	"GNE",
	"CALM3",
	"KALRN",
	"PDXK",
	"HIPK4",
	"PKN3",
	"BRSK1",
	"TAOK1",
	"SIK3",
	"NEK8",
	"FGFR4",
	"HK3",
	"MPP3",
	"IP6K3",
	"RPS6KA4",
	"CMPK1",
	"PRKAA2",
	"AK4",
	"JAK1",
	"TSSK3",
	"CAMK2N1",
	"DDR2",
	"PKDCC",
	"MAPKAPK2",
	"PMVK",
	"HIPK1",
	"STK36",
	"NEK10",
	"TGFBR2",
	"NUAK2",
	"PRKCI",
	"DCLK3",
	"RYK",
	"SNRK",
	"PRKCD",
	"CAMKV",
	"MST1R",
	"STK17A",
	"LMTK2",
	"PHKG1",
	"CDK5",
	"FASTK",
	"SYK",
	"PRKACG",
	"FXN",
	"WNK2",
	"MELK",
	"RET",
	"STK32C",
	"CKB",
	"ILK",
	"WEE1",
	"MAPK7",
	"PRKCB",
	"TK2",
	"PLK1",
	"XRCC6BP1",
	"PIP4K2C",
	"PIP5KL1",
	"CDK12",
	"FN3K",
	"SGK494",
	"AXL",
	"DAPK3",
	"ULK4",
	"MAP4K2",
	"PBK",
	"PXK",
	"DTYMK",
	"MLKL",
	"MAP2K1",
	"ROR2",
	"CSNK1G1",
	"STK32A",
	"PTK2",
	"BUB1",
	"BRD3",
	"MAP3K2",
	"SIK2",
	"ANKK1",
	"CDK1",
	"DCLK2",
	"PFKFB3",
	"TPD52L3",
	"PGK2",
	"PKIA",
	"ALK",
	"INSR",
	"PRKCE",
	"RBKS",
	"CDC42BPG",
	"KSR2",
	"CDK5R2",
	"PIK3CD",
	"EXOSC10",
	"EIF2AK3",
	"NME6",
	"TP53RK",
	"MOS",
	"OXSR1",
	"ADRBK1",
	"RELA",
	"ADCK5",
	"CKS1B",
	"MAP3K11",
	"TRIB1",
	"PEAK1",
	"PLK3",
	"TNK1",
	"BRSK2",
	"SRP72",
	"ATR",
	"PDIK1L",
	"RPS6KB2",
	"IP6K1",
	"YES1",
	"SPHK1",
	"CLK2",
	"MAP3K19",
	"CDK5R1",
	"ULK1",
	"RPS6KA3",
	"NIM1K",
	"GSG2",
	"TSSK6",
	"ERBB4",
	"ERN1",
	"GAK",
	"AURKB",
	"CLK3",
	"PSTK",
	"CSNK1A1L",
	"PAK2",
	"MAP3K15",
	"MAPK15",
	"AATK",
	"PRKAG1",
	"FES",
	"LIMK2",
	"CSF1R",
	"EPHB3",
	"LCK",
	"CAMK1D",
	"EPHA10",
	"RIPK4",
	"TBK1",
	"CHEK2",
	"PRKX",
	"KCNH8",
	"IRAK1",
	"PRKD1",
	"SRPK3",
	"EFNA5",
	"NRBP2",
	"CDK10",
	"MAPK11",
	"ROR1",
	"PRKG1",
	"THNSL1",
	"POMK",
	"GRK1",
	"PIP5K1C",
	"BCR",
	"MAGI2",
	"MAPK12",
	"PRKAR1B",
	"SBK1",
	"LRRK2",
	"DUSP21",
	"STK40",
	"STK31",
	"EPHB4",
	"PIK3R4",
	"GK2",
	"TPK1",
	"WNK3",
	"DAPK1",
	"IGF2R",
	"SRC",
	"NEK5",
	"SHPK",
	"MAP3K5",
	"IRAK4",
	"GRK6",
	"RPS6KL1",
	"UCKL1",
	"PIM3",
	"NTRK1",
	"TLK1",
	"STK39",
	"CALM1",
	"PAPSS2",
	"CDC42BPB",
	"MTOR",
	"ALPK2",
	"GK",
	"STKLD1",
	"GRK5",
	"MAP3K3",
	"BMPR2",
	"BRD2",
	"STK19",
	"CSNK2B",
	"TRIM27",
	"CDKL4",
	"STK38L",
	"TSSK1B",
	"NUP62",
	"CHUK",
	"CSNK1E",
	"PRPS1L1",
	"CKMT1B",
	"NME1",
	"PI4KA",
	"EFNA4",
	"NME2",
	"TWF2",
	"PRKDC",
	"LYN",
	"CDK3",
	"IKBKE",
	"STRADA",
	"IKBKG",
	"DGKK",
	"SGK223",
	"PIP4K2B",
	"OBSCN",
	"GUCY2EP"
	)



# List the cancer studies at server
getCancerStudies(mycgds)[,1]

# We want the "cellline_ccle_broad" study
ccle_study = "cellline_ccle_broad"

# List the case lists available for data sets
getCaseLists(mycgds,ccle_study)[,1]

# We want the CNA data
ccle_caselist = "cellline_ccle_broad_cna"

# Get available genetic profiles
ccle_geneticprofile = getGeneticProfiles(mycgds,ccle_study)[5,1]


# Get data slices for a specified list of genes, genetic profile and case list
ccle_gistic <- getProfileData(mycgds,kinase_genes,ccle_geneticprofile,ccle_caselist)

# prep ccle_gistic_amps (functionally relevant)
ccle_gistic_amps <- as.matrix(ccle_gistic)
ccle_gistic_amps[,] <- 0 
ccle_gistic_amps[which(ccle_gistic == 2)] <- 1 

# prep ccle_gistic_amps_and_gains (for exclusion)
ccle_gistic_amps_and_gains <- as.matrix(ccle_gistic)
ccle_gistic_amps_and_gains[,] <- 0 
ccle_gistic_amps_and_gains[which(ccle_gistic > 0)] <- 1 


write.table(
	ccle_gistic,
	file="CCLE_kinase_gistic_calls_150112.txt",
	col.names=TRUE,
	row.names=TRUE,
	sep="\t",
	quote=FALSE
	)


write.table(
	ccle_gistic_amps,
	file="CCLE_kinase_gistic_amps_150112.txt",
	col.names=TRUE,
	row.names=TRUE,
	sep="\t",
	quote=FALSE
	)
	
	
write.table(
	ccle_gistic_amps_and_gains,
	file="CCLE_kinase_gistic_amps_and_gains_150112.txt",
	col.names=TRUE,
	row.names=TRUE,
	sep="\t",
	quote=FALSE
	)


